//
//  ITTitleButton.m
//  coderSinaWeiBo24
//
//  Created by 张雪雪 on 16/3/24.
//  Copyright © 2016年 www.xue.com. All rights reserved.
//

#import "ITTitleButton.h"

//文字与title之前的间距
#define MARGIN 5

@implementation ITTitleButton

-(void)layoutSubviews{
    
    [super layoutSubviews];
    //先调整titleLabel的x为0
    self.titleLabel.x = 0;
    
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame) + MARGIN;
    
    self.width = self.titleLabel.width + self.imageView.width + MARGIN;
    
    self.centerX = self.superview.width * 0.5;


}
-(void)setTitle:(NSString *)title forState:(UIControlState)state{

    [super setTitle:title forState:state];

    [self sizeToFit];
}

- (void)setImage:(UIImage *)image forState:(UIControlState)state{
    
    [super setImage:image forState:state];
    
    [self sizeToFit];
}

@end
